﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace datastruct
{
   public class Queue<T>
    {
        private int rear;
        private T[] data;
        private int size;

        public Queue(int size)
        {
            this.size = size;
            this.data = new T[size];
            this.rear = 0;
        }

        public void Enqueue(T item)
        {
            if (this.rear == this.size)
            {
                throw new ArgumentOutOfRangeException();
            }         
            this.data[this.rear] = item;
            this.rear++;
        }

        public T Dequeue()
        {
            if (this.isEmpty())
            {
                throw new ArgumentOutOfRangeException();
            }
            T e = this.data[0];
            for(int i=0;i< this.rear-1; i++)
            {
                this.data[i] = this.data[i + 1];
            }
            this.rear--;

            return e;
        }

        public Boolean isEmpty()
        {
            return this.rear == 0;
        }
    }
}
